{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 0)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# divmod() 函数\n",
    "\n",
    "'''\n",
    "\n",
    "python divmod() 函数把除数和余数运算结果结合起来，返回一个包含商和余数的元组(a // b, a % b)。\n",
    "\n",
    "在 python 2.3 版本之前不允许处理复数。\n",
    "\n",
    "'''\n",
    "\n",
    "divmod(8,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "静态方法无需实例化类\n",
      "也可以实例化后调用\n"
     ]
    }
   ],
   "source": [
    "# staticmethod() 函数\n",
    "\n",
    "'''\n",
    "\n",
    "python staticmethod 返回函数的静态方法。\n",
    "\n",
    "该方法不强制要求传递参数，如下声明一个静态方法：\n",
    "\n",
    "class C(object):\n",
    "    @staticmethod\n",
    "    def f(arg1, arg2, ...):\n",
    "        ...\n",
    "以上实例声明了静态方法 f，从而可以实现实例化使用 C().f()，当然也可以不实例化调用该方法 C.f()。\n",
    "\n",
    "'''\n",
    "\n",
    "class TestStaticMethod(object):\n",
    "    @staticmethod\n",
    "    def myStaticMethod(arg = '我是静态方法'):\n",
    "        print(arg)\n",
    "    \n",
    "TestStaticMethod.myStaticMethod('静态方法无需实例化类')\n",
    "\n",
    "\n",
    "testStaticMethod = TestStaticMethod()\n",
    "testStaticMethod.myStaticMethod('也可以实例化后调用')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# all() 函数\n",
    "\n",
    "'''\n",
    "\n",
    "all() 函数用于判断给定的可迭代参数 iterable 中的所有元素是否都为 TRUE，如果是返回 True，否则返回 False。\n",
    "\n",
    "元素除了是 0、空、None、False 外都算 True。\n",
    "\n",
    "函数等价于：\n",
    "\n",
    "def all(iterable):\n",
    "    for element in iterable:\n",
    "        if not element:\n",
    "            return False\n",
    "    return True\n",
    "Python 2.5 以上版本可用。\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "语法\n",
    "以下是 all() 方法的语法:\n",
    "\n",
    "all(iterable)\n",
    "参数\n",
    "iterable -- 元组或列表。\n",
    "返回值\n",
    "如果iterable的所有元素不为0、''、False或者iterable为空，all(iterable)返回True，否则返回False；\n",
    "\n",
    "注意：空元组、空列表返回值为True，这里要特别注意。\n",
    "\n",
    "'''\n",
    "\n",
    "list1 = [1,2,'adb']\n",
    "all(list1)# 返回 true\n",
    "\n",
    "list2 = [0,1,2,'adb'] # 列表list，存在一个为0的元素\n",
    "all(list2)# 返回 false\n",
    "\n",
    "list3 = [0,1,2,'']#  列表list，存在一个为空的元素\n",
    "all(list3)# 返回 false"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 one\n",
      "0 one\n",
      "1 two\n",
      "2 three\n",
      "1 two\n",
      "0 one\n",
      "1 two\n",
      "2 three\n",
      "2 three\n",
      "0 one\n",
      "1 two\n",
      "2 three\n"
     ]
    }
   ],
   "source": [
    "#  enumerate（）\n",
    "'''\n",
    "\n",
    "enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列，同时列出数据和数据下标，一般用在 for 循环当中。\n",
    "\n",
    "Python 2.3. 以上版本可用，2.6 添加 start 参数。\n",
    "\n",
    "\n",
    "\n",
    "语法\n",
    "以下是 enumerate() 方法的语法:\n",
    "\n",
    "enumerate(sequence, [start=0])\n",
    "参数\n",
    "sequence -- 一个序列、迭代器或其他支持迭代对象。\n",
    "start -- 下标起始位置。\n",
    "返回值\n",
    "返回 enumerate(枚举) 对象。\n",
    "\n",
    "'''\n",
    "\n",
    "\n",
    "seasons = ['Spring', 'Summer', 'Fall', 'Winter']\n",
    "\n",
    "list(enumerate(seasons))\n",
    "\n",
    "\n",
    "\n",
    "# 普通的 for 循环\n",
    "i = 0\n",
    "seq = ['one', 'two', 'three']\n",
    "for element in seq:\n",
    "    print(i, seq[i])\n",
    "    i +=1\n",
    "    \n",
    "    \n",
    "# for 循环使用 enumerate\n",
    "\n",
    "    for k, element in enumerate(seq):\n",
    "        print(k,element)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
